package com.neusoft.service.impl;

import com.neusoft.mapper.EmployeeMapper;
import com.neusoft.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public List<Map<String, Object>> getDoctorByDeptIdAndLevelId(Integer departmentId, Integer registLevelId) {
        List<Map<String, Object>> doctorList= employeeMapper.getDoctorByDeptIdAndLevelId(departmentId,registLevelId);

        DayOfWeek week = LocalDateTime.now().getDayOfWeek();
        Integer amOrPm;
        if (LocalDateTime.now().getHour()>12){
            amOrPm=1;
        }else {
            amOrPm=0;
        }

        List<Map<String, Object>> selectDoctorList=new ArrayList<>();
        //从上面的的医生中选取今天出诊的医生信息返回
        for (Map<String,Object> doctor:
             doctorList) {
            String week_rule=(String) doctor.get("week_rule");
            //00 00 10 00 10 00 10

            String noon = week_rule.substring((week.getValue() - 1) * 2, (week.getValue() - 1) * 2+2);
            if (noon.charAt(amOrPm)=='1'){
                selectDoctorList.add(doctor);
            }
        }

        return selectDoctorList;
    }

    @Override
    public List<Map<String, Object>> getDoctorByDeptId(Integer departmentId) {
        return employeeMapper.selectDoctorByDeptId(departmentId);
    }
}
